(function () {

	//获取维修合同细目泵数据 服务器分页
    var contractRepairPumpData = {};
    contractRepairPumpData.contractId=jQuery('#contractId').val();
    var serverRepairPumpTable;
    jQuery(document).ready(function () {
    	serverRepairPumpTable = jQuery('#resultRepairPumpTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contract/getDevice',
                "data": function (d) {
                    return $.extend({}, d, contractRepairPumpData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildRepairPump">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'supplierCode'
                },
                {
                    data: 'productName'
                },
                {
                    data: 'productType'
                },
                {
                    data: 'subDivideType'
                },
                {
                	data: 'productModel'
                },
                {
                    data: 'number'
                },
                {
                    data: 'unitPrice'
                },
                {
                    data: 'power'
                },
                {
                    data: 'flowMaterial'
                },
                {
                    data: 'transMedia'
                },
                {
                    data: 'viscosity'
                },
                {
                    data: 'flux'
                },
                {
                    data: 'pumpLift'
                },
                {
                    data: 'temperature'
                },
                {
                    data: 'proportion'
                },
                {
                    data: 'inPressure'
                },
                {
                    data: 'effectiveNPSHA'
                },
                {
                    data: 'mustMPSHA'
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    	
    	//删除维修合同细目泵
    	jQuery('.delRepairPumpBtn').on('click', function () {
    		   var selects=getSelect("#resultRepairPumpTable",1);
    		   var url=window.rootPath+"/ui/contract/deleteDevice";
    		   var contractId = jQuery("#contractId").val(); 
    		   var totalSum = jQuery("#totalSum").val();
    		   $("#checkAllRepairPump").prop("checked", false);
    		   delSelect(selects,url,serverRepairPumpTable);
    		   var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
    		   jQuery.ajax({
               	type : 'get',
               	url : encodeURI(urlxy),
               	dataType : 'json',
               	contentType : 'application/json;charset=utf-8',
               	success : function(data) {
               		if(data==0){
               			alert("合同金额与细目的总金额相同！");
               		} else if(data==1){
               			alert("合同金额小于细目的总金额！");
               		} else if(data==2){
               			alert("合同金额大于细目的总金额！");
               		}
               	}
               });
    		});
    	
    	//新建/编辑维修合同细目泵
    	jQuery('.addRepairPumpBtn').on('click', function () {
    		var contractId = jQuery('#contractId').val();
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract('addRepairPumpBtn');
            	}
            }else{
            	showDeviceModal();
            }
    	});
    	
    	//维修合同细目泵编辑弹窗显示
    	jQuery('.editRepairPumpBtn').on('click', function () {
    		var selects=getSelect("#resultRepairPumpTable",1);
    		if(selects.length==0){
 		       $.springLemonDialog({
 		         content: '请选择需要编辑的记录',// 确认文本
 		         clickButton: function (sender, modal, index) {// 按钮事件处理
 		             $(this).closeDialog(modal);
 		         }
 		       }); 
 		    }else if(selects.length==1){
 		    	var id = selects[0].id;
				jQuery("#mainDeviceId").val(id);
				jQuery("#maincreateTime").val(selects[0].createTime);
				jQuery("#productName").val(selects[0].productName);
				jQuery("#productType").val(selects[0].productType);
				jQuery("#subDivideType").empty();
				var url=window.rootPath+"/ui/contract/getDeviceOption/"+selects[0].productType;
        		jQuery.ajax({
        			url:  encodeURI(url),
        			cache:false,
                    type: 'get',
                    dataType: 'json',
                    success: function (data) {
                    	var options = data.options;
                    	for (var i=0; i<options.length; i++ ) 
                    	{ 
                    		var option = $("<option>").text(options[i]).val(options[i])
                    	    jQuery("#subDivideType").append(option);
                    	}
                    	jQuery("#subDivideType").val(selects[0].subDivideType);
                		jQuery("#productModel").val(selects[0].productModel);
        				jQuery("#number").val(selects[0].number);
        				jQuery("#unitPrice").val(selects[0].unitPrice);
        				jQuery("#power").val(selects[0].power);
        				jQuery("#viscosity").val(selects[0].viscosity);
        				jQuery("#flowMaterial").val(selects[0].flowMaterial);
        				jQuery("#transMedia").val(selects[0].transMedia);
        				jQuery("#proportion").val(selects[0].proportion);
        				jQuery("#NPSHA").val(selects[0].effectiveNPSHA);
        				jQuery("#flux").val(selects[0].flux);
        				jQuery("#temperature").val(selects[0].temperature);
        				jQuery("#MPSHA").val(selects[0].mustMPSHA);
        				jQuery("#pumpLift").val(selects[0].pumpLift);
        				jQuery("#inPressure").val(selects[0].inPressure);
        				jQuery('#oneSupplierCode').val(selects[0].supplierCode);
        				if(selects[0].dDeliveryDate != null && selects[0].dDeliveryDate　!= ""){
        					jQuery("#dDeliveryDate").val(moment(selects[0].dDeliveryDate).format('YYYY-MM-DD'));
        				}else{
        					jQuery("#dDeliveryDate").val('');
        				}
        				jQuery('#moreSupplierCode').val('');
        	  			jQuery('#ids').val('');
        	  			jQuery("#selectContractId").val('');
        	  			document.getElementById("editOneDeviceAtrrForm").style.display='block';
        	  			document.getElementById("editMoreDeviceAtrrForm").style.display='none';
          			    jQuery('#mainDeviceModal').modal('show');
                    }
        		});
   		    }else{
   		    	var ids=selects[0].id;
   		    	for(var i=1;i<selects.length;i++){
   		    		ids += ',' + selects[i].id;  
   		    	}
  			    jQuery('#ids').val(ids);
  			    jQuery("#mainDeviceId").val('');
  			    jQuery("#maincreateTime").val('');
				jQuery("#productName").val('');
				jQuery("#productModel").val('');
				jQuery("#number").val('');
				jQuery("#unitPrice").val('');
				jQuery("#power").val('');
				jQuery("#viscosity").val('');
				jQuery("#flowMaterial").val('');
				jQuery("#transMedia").val('');
				jQuery("#proportion").val('');
				jQuery("#NPSHA").val('');
				jQuery("#flux").val('');
				jQuery("#temperature").val('');
				jQuery("#MPSHA").val('');
				jQuery("#pumpLift").val('');
				jQuery("#inPressure").val('');
				jQuery('#oneSupplierCode').val('');
				jQuery('#moreSupplierCode').val('');
				jQuery("#selectContractId").val('');
				jQuery("#dDeliveryDate").val('');
  			    document.getElementById("editMoreDeviceAtrrForm").style.display='block';
  			    document.getElementById("editOneDeviceAtrrForm").style.display='none';
  			    jQuery('#mainDeviceModal').modal('show');
 		    }
 		});
    	
    	///下拉框产品类型改变////
		jQuery('#productType').trigger('change');///自动触发下拉框
		
		jQuery('#productType').change(function(){
			var productType = jQuery("#productType").val();
			jQuery("#subDivideType").empty();
			var url=window.rootPath+"/ui/contract/getDeviceOption/"+productType;
    		jQuery.ajax({
    			url:  encodeURI(url),
    			cache:false,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                	var options = data.options;
                	for (var i=0; i<options.length; i++ ) 
                	{ 
                		var option = $("<option>").text(options[i]).val(options[i])
                	    jQuery("#subDivideType").append(option);
                	}
                }
    		})
		});
		
		//新建/编辑泵保存
		jQuery(".saveDeviceBtn").on("click", function() {
			$("#checkAllRepairPump").prop("checked", false);
			//单个泵保存
    		if(jQuery("#editOneDeviceAtrrForm").css("display")=='block' && jQuery("#editMoreDeviceAtrrForm").css("display")=='none'){
    			if(jQuery("#editOneDeviceAtrrForm") && !jQuery("#editOneDeviceAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
                    return;
                };
                jQuery(".saveDeviceBtn").attr("disabled", true);
                var url = window.rootPath + '/ui/contract/editOneDevice';
                var totalSum = jQuery("#totalSum").val();
    			var id = jQuery("#mainDeviceId").val();
    			var createTime = jQuery("#maincreateTime").val();
    			var productName = jQuery("#productName").val();
    			var subDivideType = jQuery("#subDivideType").val();
    			var productType = jQuery("#productType").val();
    			var productModel = jQuery("#productModel").val();
    			var number = jQuery("#number").val();
    			var unitPrice = jQuery("#unitPrice").val();
    			var power = jQuery("#power").val();
    			var flowMaterial = jQuery("#flowMaterial").val();
    			var transMedia = jQuery("#transMedia").val();
    			var viscosity = jQuery("#viscosity").val();
    			var flux = jQuery("#flux").val();
    			var pumpLift = jQuery("#pumpLift").val();
    			var temprature = jQuery("#temperature").val();
    			var proportion = jQuery("#proportion").val();
    			var inPressure = jQuery("#inPressure").val();
    			var NPSHA = jQuery("#NPSHA").val();
    			var MPSHA = jQuery("#MPSHA").val();
    			var contractId = jQuery("#contractId").val();
    			var contractType = "维修合同";
    			var dDeliveryDate = jQuery("#dDeliveryDate").val();
    			var selectContractId = jQuery("#selectContractId").val();
      			var oneSupplierCode = jQuery("#oneSupplierCode").val();
      			//暂时将选择关联的项目合同ID与合同号存在数据的supplierCode中，方便使用；
    			if (id == '') {
    				var d = {
    					"supplierCode":selectContractId+":"+oneSupplierCode,
    					"productName" : productName,
    					"productType" : productType,
    					"subDivideType" : subDivideType,
    					"productModel" : productModel,
    					"number" : number,
    					"unitPrice" : unitPrice,
    					"power" : power,
    					"flowMaterial" : flowMaterial,
    					"transMedia" : transMedia,
    					"viscosity" : viscosity,
    					"flux" : flux,
    					"pumpLift" : pumpLift,
    					"temperature" : temprature,
    					"proportion" : proportion,
    					"inPressure" : inPressure,
    					"effectiveNPSHA" : NPSHA,
    					"mustMPSHA" : MPSHA,
    					"contractType":contractType,
    					"dDeliveryDate":dDeliveryDate,
    					"contractID" : contractId
    				};
    			} else {
    				var d = {
    					"id" : id,
    					"createTime" : createTime,
    					"supplierCode":selectContractId+":"+oneSupplierCode,
    					"productName" : productName,
    					"productType" : productType,
    					"subDivideType" : subDivideType,
    					"productModel" : productModel,
    					"number" : number,
    					"unitPrice" : unitPrice,
    					"power" : power,
    					"flowMaterial" : flowMaterial,
    					"transMedia" : transMedia,
    					"viscosity" : viscosity,
    					"flux" : flux,
    					"pumpLift" : pumpLift,
    					"temperature" : temprature,
    					"proportion" : proportion,
    					"inPressure" : inPressure,
    					"effectiveNPSHA" : NPSHA,
    					"mustMPSHA" : MPSHA,
    					"contractType":contractType,
    					"dDeliveryDate":dDeliveryDate,
    					"contractID" : contractId
    				};
    			}
    			var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
    			jQuery.ajax({
    				type : 'post',
    				url : encodeURI(url),
    				data : JSON.stringify(d),
    				dataType : 'json',
    				contentType : 'application/json;charset=utf-8',
    				success : function(data) {
    					jQuery("#mainDeviceModal").modal('hide');
    					contractRepairPumpData.contractId=jQuery('#contractId').val();
    					serverRepairPumpTable.draw(true);
    					jQuery(".saveDeviceBtn").attr("disabled", false);
    					jQuery.ajax({
    						type : 'get',
    						url : encodeURI(urlxy),
    						dataType : 'json',
    						contentType : 'application/json;charset=utf-8',
    						success : function(data) {
    							if(data==0){
    								alert("合同金额与细目的总金额相同！");
    							} else if(data==1){
    								alert("合同金额小于细目的总金额！");
    							} else if(data==2){
    								alert("合同金额大于细目的总金额！");
    							}
    						}
    					});
    				}
    			});
    		}
    		//多个泵保存
    		else if(jQuery("#editOneDeviceAtrrForm").css("display")=='none' && jQuery("#editMoreDeviceAtrrForm").css("display")=='block'){
    			if(jQuery("#editMoreDeviceAtrrForm") && !jQuery("#editMoreDeviceAtrrForm").Validform({tiptype:3, showAllError:true}).check(false)){
                    return;
                };
                jQuery(".saveDeviceBtn").attr("disabled", true);
                var totalSum = jQuery("#totalSum").val();
                var contractId = jQuery("#contractId").val();
                var ids = jQuery('#ids').val();
                var selectContractId = jQuery("#selectContractId").val();
                var url=window.rootPath+"/ui/contract/editMoreDevice"+"?deviceInfo="+ ids +":"+ selectContractId;
                var urlxy = window.rootPath + '/ui/contract/checkMoney?contractId=' + contractId + '&totalSum=' + totalSum;
                jQuery.ajax({
                    url:encodeURI(url),
                    cache:false,
                    type : "get",
                    dataType:"json",
                    success:function(data){
                    	jQuery('#mainDeviceModal').modal('hide');
                    	serverRepairPumpTable.draw(false);
                    	jQuery(".saveDeviceBtn").attr("disabled", false);
                    	jQuery.ajax({
    						type : 'get',
    						url : encodeURI(urlxy),
    						dataType : 'json',
    						contentType : 'application/json;charset=utf-8',
    						success : function(data) {
    							if(data==0){
    								alert("合同金额与细目的总金额相同！");
    							} else if(data==1){
    								alert("合同金额小于细目的总金额！");
    							} else if(data==2){
    								alert("合同金额大于细目的总金额！");
    							}
    						}
    					});
                    }
                });
    		}
			
		});
    	
    	//EXCEL导入
        jQuery('.importRepairPumpList').on("click",function()
        {
        	var contractId = jQuery('#contractId').val();
        	var type = '3';
        	if(contractId == ""){
            	if (confirm("当前合同还未保存，是否保存？")) {
            		saveContract("importRepairPumpList");
            	}
            }else{
            	fileUpload(contractId, type);
            }
        });
        
        /**
    	 * 保存维修合同
    	 */
        var saveContract = function(state) {
        	var signedDate = jQuery('#signedDate').val();
        	var giveOutDate = jQuery('#giveOutDate').val();
        	var scheduleDate = jQuery('#scheduleDate').val();
         	var repairDate = jQuery('#repairDate').val();
     		var operatDate = jQuery('#operatDate').val();
     		if (signedDate==""||giveOutDate==""||repairDate==""||operatDate==""){
     			message("请将页面上所有日期信息完善，保存后还可进行编辑。");
     			return ;
     		}
     		var isId=jQuery("#contractId").val();
     		var contractcreateTime=jQuery("#createTime").val();
      	    var createTime=new Date(contractcreateTime).getTime();
            var supplierCode = jQuery('#supplierCode').val();
        	var demanderCode = jQuery('#demanderCode').val();
        	var contractType = jQuery('#contractType').val();
     		var totalSum = jQuery('#totalSum').val();
     		var repairCode = jQuery('#repairCode').val();
 			var repairNumber = jQuery('#repairNumber').val();
 			var repairKind = jQuery('#repairKind').val();
     		var projectCode = jQuery('#projectCode').val();
     		var stop = jQuery('#stop').val();
     		var freightCharge = jQuery('#freightCharge').val();
     		var projectName = jQuery('#projectName').val();
         	var payType = jQuery('#payType').val();
         	var guaranteePeriod = jQuery('#guaranteePeriod').val();
         	var breakDuty = jQuery('#breakDuty').val();
         	var customerId = jQuery("#customerId").val();
     		var orderUnit = jQuery('#orderUnit').val();
         	var orderDelegate = jQuery('#orderDelegate').val();
     		var orderPhone = jQuery('#orderPhone').val();
     		var industryInfo = jQuery('#industryInfo').val();
     		var orderAddress = jQuery('#orderAddress').val();
     		var orderZip = jQuery('#orderZip').val();
     		var orderArea = jQuery('#orderArea').val();
     		var invoiceBank = jQuery("#invoiceBank").val();
      		var bankAccount = jQuery("#bankAccount").val();
      		var taxNumber = jQuery("#taxNumber").val();
      		var invoiceAddress = jQuery("#invoiceAddress").val();
     		var postUnit = jQuery('#postUnit').val();
         	var postDelegate = jQuery('#postDelegate').val();
     		var postPhone = jQuery('#postPhone').val();
     		var postAddress = jQuery('#postAddress').val();
     		var postZip = jQuery('#postZip').val();
     		var dutyArea = jQuery('#dutyArea').val();
     		var dutyOfficer = jQuery('#dutyOfficer').val();
     		var southNorthArea = jQuery('#southNorthArea').val();
     		var belongArea = jQuery('#belongArea').val();
     		var checkKind = jQuery('#checkKind').val();
     		var productKind = jQuery('#productKind').val();
     		var signOfficer = jQuery('#signOfficer').val();
     		var repairOfficer = jQuery('#repairOfficer').val();
     		var quotationOfficer = jQuery('#quotationOfficer').val();
     		var operatDepartment = jQuery('#operatDepartment').val();
     		var operator = jQuery('#operator').val();
     		var memo = jQuery('#memo').val();
     		var state = jQuery('#state').val();
     		var cstate = jQuery('#cstate').val();
     		if(isId == ""){// 新增合同
     			var d = {
         				"user":{"id":$("#userId").val()},
                    	"supplierCode": supplierCode,
                    	"demanderCode": demanderCode,
                    	"contractType": contractType,
                        "totalSum": totalSum,
                        "signedDate": signedDate,
                        "scheduleDate": scheduleDate,
                        "giveOutDate": giveOutDate,
                        "repairCode": repairCode,
                        "repairNumber": repairNumber,
                        "repairKind": repairKind,
                        "repairDate": repairDate,
                        "projectCode": projectCode,
                        "stop": stop,
                        "freightCharge": freightCharge,
                        "projectName": projectName,
                        "payType": payType,
                        "guaranteePeriod": guaranteePeriod,
                        "breakDuty": breakDuty,
                        "customerId": customerId,
                        "orderUnit": orderUnit,
                        "orderDelegate": orderDelegate,
                        "orderPhone": orderPhone,
                        "industryInfo": industryInfo,
                        "orderAddress": orderAddress,
                        "orderZip": orderZip,
                        "orderArea": orderArea,
                        "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
                        "postUnit": postUnit,
                        "postDelegate": postDelegate,
                        "postPhone": postPhone,
                        "postAddress": postAddress,
                        "postZip": postZip,
                        "dutyArea": dutyArea,
                        "dutyOfficer": dutyOfficer,
                        "southNorthArea": southNorthArea,
                        "belongArea": belongArea,
                        "checkKind": checkKind,
                        "productKind": productKind,
                        "signOfficer": signOfficer,
                        "repairOfficer": repairOfficer,
                        "quotationOfficer": quotationOfficer,
                        "operatDepartment": operatDepartment,
                        "operator": operator,
                        "operatDate": operatDate,
                        "memo": memo,
                        "state": state,
                        "cstate": cstate,
                };
     		}else{
     			var d = {
     					"id": isId,
  	        			"createTime": createTime,
                    	"supplierCode": supplierCode,
                    	"demanderCode": demanderCode,
                    	"contractType": contractType,
                        "totalSum": totalSum,
                        "signedDate": signedDate,
                        "scheduleDate": scheduleDate,
                        "giveOutDate": giveOutDate,
                        "repairCode": repairCode,
                        "repairNumber": repairNumber,
                        "repairKind": repairKind,
                        "repairDate": repairDate,
                        "projectCode": projectCode,
                        "stop": stop,
                        "freightCharge": freightCharge,
                        "projectName": projectName,
                        "payType": payType,
                        "guaranteePeriod": guaranteePeriod,
                        "breakDuty": breakDuty,
                        "customerId": customerId,
                        "orderUnit": orderUnit,
                        "orderDelegate": orderDelegate,
                        "orderPhone": orderPhone,
                        "industryInfo": industryInfo,
                        "orderAddress": orderAddress,
                        "orderZip": orderZip,
                        "orderArea": orderArea,
                        "invoiceBank": invoiceBank,
      	                "bankAccount": bankAccount,
      	                "taxNumber": taxNumber,
      	                "invoiceAddress": invoiceAddress,
                        "postUnit": postUnit,
                        "postDelegate": postDelegate,
                        "postPhone": postPhone,
                        "postAddress": postAddress,
                        "postZip": postZip,
                        "dutyArea": dutyArea,
                        "dutyOfficer": dutyOfficer,
                        "southNorthArea": southNorthArea,
                        "belongArea": belongArea,
                        "checkKind": checkKind,
                        "productKind": productKind,
                        "signOfficer": signOfficer,
                        "repairOfficer": repairOfficer,
                        "quotationOfficer": quotationOfficer,
                        "operatDepartment": operatDepartment,
                        "operator": operator,
                        "operatDate": operatDate,
                        "memo": memo,
                        "state": state,
                        "cstate": cstate,
                };
     		}
     		jQuery(".addRepairPumpBtn").attr("disabled", true);
      		jQuery(".importRepairPumpList").attr("disabled", true);
      		jQuery(".addRepairOtherBtn").attr("disabled", true);
      		jQuery(".importRepairOtherList").attr("disabled", true);
      		var id=isId;
      		if (id==null||id==''){
      			id = 'null';
      		}
      		if (cstate=="已完成"){
      			$.springLemonDialog({
  					content : '该合同已经生产商品计划，不能保存！',// 确认文本
  					clickButton : function(sender, modal, index) {// 按钮事件处理
  						$(this).closeDialog(modal);
  					}
      			});
  			}
      		if(cstate=="已排产"){
      			alert("保存合同后将修改排产相关信息。");
      		}
      		if (supplierCode!=''){// 验证供方合同号是否已存在
      			var urlValid=window.rootPath+"/ui/contract/validSupplierCode/"+id+"/"+supplierCode;
      	    	jQuery.ajax({
      	            url:encodeURI(urlValid),
      	            cache:false,
      	            type :"get",
      	            dataType:"json",
      	            contentType:"application/json;charset=utf-8",// 解决返回数据中的中文乱码问题
      	            success:function(data){
      	            	if(data.codeState==1){
      	            		$.springLemonDialog({
     		      		         content: '供方合同号已存在，请修改！',// 确认文本
     		      		         clickButton: function (sender, modal, index) {// 按钮事件处理
     		      		             $(this).closeDialog(modal);
     		      		         }
     		            		});
      	            		jQuery(".addRepairPumpBtn").attr("disabled", false);
      	            		jQuery(".importRepairPumpList").attr("disabled", false);
      	            		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	            		jQuery(".importRepairOtherList").attr("disabled", false);
      	            		return;
      	            	}
      	                    var url = window.rootPath + "/ui/contract/saveContractRepair";
      	                    jQuery.ajax({
      	                        type: 'post',
      	                        url: url,
      	                        data: JSON.stringify(d),
      	                        dataType: 'json',
      	                        contentType: 'application/json;charset=utf-8',
      	                        success: function (data) {
      	                        	var contractId = data.contractId;
      	                        	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
      	                        	jQuery("#createTime").val(time);
      	                        	jQuery("#contractId").val(contractId);
      	                        	jQuery(".addRepairPumpBtn").attr("disabled", false);
      	                    		jQuery(".importRepairPumpList").attr("disabled", false);
      	                    		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	                    		jQuery(".importRepairOtherList").attr("disabled", false);
      	                        	if (state=="addRepairPumpBtn"){
      	                        		showDeviceModal();
      	                        	}else if(state=="importRepairPumpList"){
      	                        		var type = '3';
      	                        		fileUpload(contractId, type);
      	                        	}
      	                        }
      	                    });
      	            }
      	    	});
      		}else{
      	            var url = window.rootPath + "/ui/contract/saveContractRepair";
      	            jQuery.ajax({
      	                type: 'post',
      	                url: url,
      	                data: JSON.stringify(d),
      	                dataType: 'json',
      	                contentType: 'application/json;charset=utf-8',
      	                success: function (data) {
      	                	var contractId = data.contractId;
      	                	var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
	                        jQuery("#createTime").val(time);
      	                	jQuery("#contractId").val(contractId);
      	                	jQuery(".addRepairPumpBtn").attr("disabled", false);
      	            		jQuery(".importRepairPumpList").attr("disabled", false);
      	            		jQuery(".addRepairOtherBtn").attr("disabled", false);
      	            		jQuery(".importRepairOtherList").attr("disabled", false);
	                        if (state=="addRepairPumpBtn"){
	                        	showDeviceModal();
	                       	}else if(state=="importRepairPumpList"){
  	                        	var type = '3';
  	                       		fileUpload(contractId, type);
  	                       	}
      	                }
      	            });
      		}
        }
        
        /**
    	 * 添加泵时初始化弹窗
    	 */
        var showDeviceModal = function() {
        	var productType = jQuery("#productType :selected").text();
        	jQuery("#subDivideType").empty();
        	var url=window.rootPath+"/ui/contract/getDeviceOption/"+productType;
    		jQuery.ajax({
    			url:  encodeURI(url),
    			cache:false,
                type: 'get',
                dataType: 'json',
                success: function (data) {
                	var options = data.options;
                	for (var i=0; i<options.length; i++ ) 
                	{ 
                		var option = $("<option>").text(options[i]).val(options[i])
                	    jQuery("#subDivideType").append(option);
                	} 
                    jQuery("#mainDeviceId").val('');
                    jQuery("#maincreateTime").val('');
    				jQuery("#productName").val('');
    				jQuery("#productModel").val('');
    				jQuery("#number").val('');
    				jQuery("#unitPrice").val('');
    				jQuery("#power").val('');
    				jQuery("#viscosity").val('');
    				jQuery("#flowMaterial").val('');
    				jQuery("#transMedia").val('');
    				jQuery("#proportion").val('');
    				jQuery("#NPSHA").val('');
    				jQuery("#flux").val('');
    				jQuery("#temperature").val('');
    				jQuery("#MPSHA").val('');
    				jQuery("#pumpLift").val('');
    				jQuery("#inPressure").val('');
    				jQuery('#oneSupplierCode').val('');
    				jQuery('#moreSupplierCode').val('');
          			jQuery('#ids').val('');
          			jQuery("#selectContractId").val('');
    				document.getElementById("editOneDeviceAtrrForm").style.display='block';
          			document.getElementById("editMoreDeviceAtrrForm").style.display='none';
    				jQuery("#mainDeviceModal").modal('show');
                }
            });
        }
    	
    	/**
    	 * 文件上传插件
    	 */
    	var fileUpload = function(contractId, type) {
    		var root = window.rootPath;
    		WebFilesUploader(
    				{
    					_webuploader : {
    						server : root + '/ui/contract/import/' + contractId +'/'+ type,
    						swf : root
    								+ '/resources/poweradminjs/webupload/webfilesuploader/Uploader.swf',
    						chunked:false		
    					}
    				
    				}, function(jsons) {  		
    					contractRepairPumpData.contractId=jQuery('#contractId').val();
    					serverRepairPumpTable.draw(true);
    				});
    	};
    	
    	//列表中的全选
        $("#checkAllRepairPump").click(function(){
        	var check = $(this).prop("checked");
            $(".checkchildRepairPump").prop("checked", check);
    	});
    	
    });
})();